#include "arcs_error.h"

Point Circle::GetArcMidpoint(double theta1,double theta2) const{

    double thetamid = (theta1 + theta2) / 2.0;

    Point mid;

    mid.x = center.x + radius * cos(thetamid);

    mid.y = center.y + radius * sin(thetamid);

    return mid;

}

std::vector<Point> Circle::CalculateIntersections(const Circle &other) const{

        std::vector<Point> intersections;

        double dist = Distance(this->center,other.center);

        if (dist > radius + other.radius || dist < fabs(radius - other.radius)||(dist == 0 && this->radius == other.radius)){
            return intersections;
        }

        double dist_a = (this->radius * this->radius - other.radius * other.radius + dist * dist) / (2 * dist);

        double dist_h = sqrt(this->radius * this->radius - dist_a * dist_a);

        Point point_m;

        double dx = (other.center.x - this->center.x);

        double dy = (other.center.y - this->center.y);

        double point_m_x = this->center.x + dist_a * (dx / dist);

        double point_m_y = this->center.y + dist_a * (dy / dist);

        Point intersect1,intersect2;

        intersect1.x = point_m.x + dist_h * (dy / dist);

        intersect1.y = point_m.y - dist_h * (dx / dist);

        intersect2.x = point_m.x - dist_h * (dy / dist);

        intersect2.y = point_m.y + dist_h * (dx / dist);

        intersections.push_back(intersect1);

        if(dist != this->radius + other.radius){
            intersections.push_back(intersect1);
        }

       return intersections;
}

double RandomDouble(double min, double max) {

    static std::mt19937 generator(static_cast<unsigned int>(std::time(nullptr)));

    std::uniform_real_distribution<double> distribution(min, max);

    return distribution(generator);
}








